﻿using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.UI.Base;
using Habanero.UI.Win;
using UseCaseManager.BO;

namespace UseCaseManager.UI
{
    /// <summary>
    /// A grid control used for adding and editing Drops.
    /// Release that Drop belongs to is specified. 
    /// </summary>
    public class DropsGridControlShowsRelease : UserControlWin, IFormControl
    {
        private readonly IControlFactory _controlFactory;

        /// <summary>
        /// Returns the ReadOnlyGridControl that is being used for showing and editing Drops in this control
        /// </summary>
        public IGridControl GridSelector { get; private set; }

        public DropsGridControlShowsRelease(IControlFactory controlFactory)
        {
            _controlFactory = controlFactory;

            // Create the read-only grid
            GridSelector = _controlFactory.CreateReadOnlyGridControl();

            // Used to specify a custom UI def
            GridSelector.Initialise(ClassDef.Get<Drop>(), "DropCompletionStatus");

            // Load the collection of Drops.  You can set the criteria and order by values here.
            BusinessObjectCollection<Drop> sampleCollection = Broker.GetBusinessObjectCollection<Drop>("", "EndDate");
            GridSelector.BusinessObjectCollection = sampleCollection;

            // Set this to true to enable the filters, then add your filters below (see commented out line)
            GridSelector.FilterControl.Visible = false;
            //dropGridControl.FilterControl.AddStringFilterTextBox("", "");

            // Uncomment this line to enable the default delete button
            ((ReadOnlyGridControlWin)GridSelector).Buttons.ShowDefaultDeleteButton = true;

            // Add the grid to the control so that it fills the control
            BorderLayoutManager layoutManager = _controlFactory.CreateBorderLayoutManager(this);
            layoutManager.AddControl(GridSelector, BorderLayoutManager.Position.Centre);
        }

         public DropsGridControlShowsRelease():this(GlobalUIRegistry.ControlFactory)
        {
            
        }

         /// <summary>
         /// Called whenever the control is placed on a form by the menu system.  Put any initialisation
         /// code in here that must be run whenever the form is displayed.
         /// </summary>
         public void SetForm(IFormHabanero form) { }
    }
}
